﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
#endregion

namespace BreakOutBattles.Sound
{
    #region Enums
    public enum SoundEffects
    {
        ROUND_START,
        PADDLE_HIT,
        BRICK_HIT_1,
        POWER_UP_1,
        POWER_UP_2,
        GAME_OVER,
        GAME_WIN,
        MENU_NAVIGATE
    }
    #endregion

    public static class SoundManager
    {
        #region Fields
        private static string waveBankName = @"\Sounds\Wave Bank.xwb";
        private static string soundbankName = @"\Sounds\Sound Bank.xsb";
        private static string settingsFile = @"\Sounds\BreakoutBattleSounds.xgs";

        private static AudioEngine audioEngine = null;
        private static WaveBank waveBank = null;
        private static SoundBank soundBank = null;

        private static Dictionary<SoundEffects, string> effectsLib;
        #endregion


        /// <summary>
        /// Initializes the sound engine.
        /// </summary>
        /// <param name="rootDirectory">The root path to the content directory of the game.</param>
        public static void Initialize(string rootDirectory)
        {
            //Initialize sound engine
            audioEngine = new AudioEngine(rootDirectory + settingsFile);
            waveBank = new WaveBank(audioEngine, rootDirectory + waveBankName);
            soundBank = new SoundBank(audioEngine, rootDirectory + soundbankName);

            //Build effects library
            effectsLib = new Dictionary<SoundEffects, string>();
            effectsLib[SoundEffects.ROUND_START] = "roundStart";
            effectsLib[SoundEffects.PADDLE_HIT] = "paddleHit";
            effectsLib[SoundEffects.BRICK_HIT_1] = "brickHit1";
            effectsLib[SoundEffects.POWER_UP_1] = "powerUp1";
            effectsLib[SoundEffects.POWER_UP_2] = "powerUp2";
            effectsLib[SoundEffects.GAME_OVER] = "gameOver";
            effectsLib[SoundEffects.MENU_NAVIGATE] = "menuOption";
        }

        /// <summary>
        /// Plays a sound effect.
        /// </summary>
        /// <param name="soundEffect">The SoundEffect to play.</param>
        public static void PlayEffect(SoundEffects soundEffect)
        {
            soundBank.GetCue(effectsLib[soundEffect]).Play();
        }

    }
}
